Pattern Scroller
Volume Number: 6
Issue Number: 12
Column Tag: Pascal Procedures
By Shelly Mendlinger, Brooklyn, NY
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
These programs are written in Borland’s Turbo Pascal. Don’t worry! Borland’s
implementation is straightforward and virtually straight out of Inside Macintosh
(IM), Vol . I, II and IV. Perhaps the compiler directives need explanation.
{1}
{$D+} Turn on Generate Debug Symbols. Puts procedure names in the
object code.
{$R ResFileName } Define Resource File.
{$U-} Turn off Use Standard Units. Units PasInOut and PasConsole not
automatically complied.
PatternsScroller
PatternsScroller(fig. 1) creates a scrollable pattern list showing eight patterns
at a time. Click in a pattern to select it. The selection is echoed in the test rectangle to
prove the data has been correctly retrieved. This program came about by playing-I
mean experimenting-with the List Manager Package(IM vol. IV) to solve a problem:
give access the 38 patterns in the System’s ‘PAT#’ resource while taking minimal
screen space. Obviously, the MacPaint style of 2 rows of 19 patterns across the
screen would not do. The solution is scrollable patterns. Showing several small
squares of patterns and a scroll bar requires little screen area.
The two dozen or so routines of the List Manager handle the tedious chores of list
maintenance and appearance such as drawing, storing and retrieving data, selecting,
hiliting, scrolling, resizing, updating, activating. Quite an impressive list!
PatternScroller utilizes the List Manager to manipulate non-text data(8-byte
QuickDraw patterns). Since the default routines draw list data as text and invert to
hilite selections, a new LDEF(List DEFinition) resource customized for patterns needs
to be created. The second program, Pas_to_ResCode.LDEF, does this and writes the code
to the specified resource file.
The Terminology
First, we discuss List Manager terminology. A list is a set of elements containing
data of variable sizes. A cell is a screen rectangle that displays an element’s data; it’s
basic unit of the list interface. Cell is also a data type (the equivalent of type point)
that describes a (screen)cell’s two dimensional position in the list. The first cell is in
column one, row one (the top most, left most position) and has coordinates (0,0),
actually the position of its top-left corner in the list’s cell grid. To avoid confusion,
remember a cell’s coordinates are (column - 1, row - 1). Be aware that some List
Manager variables are in terms of cells and some in terms pixels. Hopefully, these
will be clarified as we go through the subroutines of PatternScroller (Listing 2) in
the order they are called.
Initialize: Initializes the usual managers and sets up a window to show the list.
The Dialog Manager is not initialized and does not seem to be needed by the List
Manager.
SetUpList: Calling LNew initiates the List Manager by loading in into memory
and creating a list record data structure that includes the values passed in its nine
parameters:
rView: Type rect. In local coordinates, the box in which the list is to be drawn.
Its size determines the number of cells visible.
dataBounds: Type rect. In terms of cells, the initial dimensions of the list
array. The first values are 0,0, the next two are the number of columns and rows of
cells making up the list. Here it’s 38 columns across, 1 row down.
cSize: Type point. Holds the width and height in pixels of the basic cell. All
cells in a given list have identical dimensions, no matter what the length of the data
held.
theProc: Type integer. The ID of the LDEF resource to be used; the default ID =
0. Here it’s assigned the value of LDefNum, declared as a constant for easy changing.
theWindow: Type windowPtr. The window in which the list is to be drawn.